home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93a.txt
/
000015_icon-group-sender _Tue Jan 12 14:01:08 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1993-04-21
|
2KB
Received: by cheltenham.cs.arizona.edu; Tue, 12 Jan 1993 19:25:33 MST
Date: Tue, 12 Jan 93 14:01:08 CST
From: "Richard L. Goerwitz" <goer@midway.uchicago.edu>
Message-Id: <9301122001.AA21292@midway.uchicago.edu>
To: icon-group@cs.arizona.edu
Subject: Pattern matching
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
>Would it be feasible to have {SML, Miranda, Hope blabla}-style pattern
>matching in Icon. (More specifically, a case state that has patterns
>instead of literals in the cases.) I think it would fit in neatly
>with the data constructors Icon has, and greatly increase its
>useability for writing things like compilers in Icon, where you want
>to branch on the structure of some data object rather than on a
>specific object.
There are just so many bits of syntactic sugar one can add to a language
before it becomes bloated. Maybe I'm not understanding correctly what
you mean, but I don't see anything wrong with:
while line := read() do {
line ? {
if match("this") then
X
else if match("that") then
Y
else if match("something else") then
Z
}
}
Anyone who knows Icon will immediately recognize this code fragment as
implementing a case-like structure for patterns rather than values.
Writing a compiler, though, really requires more than a simple set of
scanning routines, so I'm not sure that this is what you want either.
In most cases, deterministic lexical analyzers have to work on a charac-
ter-by-character basis, with little or no backtracking. The lexical
analyzers then feed tokens to parsers that operate on stack structures,
and don't read the input stream as such. I keep hoping somebody with
more theoretical background than I will post a good compiler compiler for
Icon some day.
-Richard Goerwitz
goer@midway.uchicago.edu